import { CoolController, BaseController, QueryOp } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { PixPromotionPlatformEntity } from '../../entity/info';
import { PixPromotionPlatformService } from '../../service/info';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';

/**
 * pix模块-推广平台信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: PixPromotionPlatformEntity,
  service: PixPromotionPlatformService,
  pageQueryOp: {
    keyWordLikeFields: ['b.name', 'a.userId', 'a.status'],
    select: ['a.*', 'b.name as userName'],
    join: [
      {
        entity: BaseSysUserEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
      },
    ],
  },
})
export class AdminPixPromotionPlatformController extends BaseController {
  @Inject()
  pixPromotionPlatformService: PixPromotionPlatformService;

  async page() {
    const { body } = this.baseCtx.request;
    const op = {} as QueryOp
    op.where = async (ctx) => {
      return [
        [
          { userId: ctx.admin.userId },
        ],
      ];
    }
    return this.ok(await this.service.page(body, op, this.connectionName));
  }
}
